// 动态配置html-webpack-plugin插件
const glob = require('glob');//glob，这个是一个全局的模块，动态配置多页面会用得着
const HtmlWebpackPlugin = require('html-webpack-plugin');
const isDev = process.env.NODE_ENV === 'development';
const path = './src';

let setHtml = () => {
	let htmloptions = [];
	//读取src目录所有的page入口
	glob.sync(`${path}/pages/*/*.html`).forEach(name => {
		let index1 = name.lastIndexOf('/');
		let index2 = name.lastIndexOf('/',index1-1)
		let entryname = name.substring(index2+1, index1);
		let htmlplugins = new HtmlWebpackPlugin({
			template: name,
			filename: isDev ? `${entryname}/index.html` : `${entryname}.html`,
			minify: {
				removeAttributeQuotes: false, //是否删除属性的双引号
				collapseWhitespace: false,	//是否折叠空白
			},
			// hash: true	//是否加上hash，默认是false]
			// config: config.template,
			chunks: [entryname]
		})
		htmloptions.push(htmlplugins)
	})
	return htmloptions;
}

module.exports = setHtml;